{
 "cells": [
  {
   "cell_type": "markdown",
   "id": "302c29f6",
   "metadata": {},
   "source": [
    "## 链表中两两交换节点\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "aaed35bc",
   "metadata": {},
   "outputs": [],
   "source": [
    "class ListNode:\n",
    "    def __init__(self,val=0,next=None):\n",
    "        self.val = val\n",
    "        self.next = next\n",
    "\n",
    "class Solution:\n",
    "    def swapPairs(self,head:ListNode) -> ListNode:\n",
    "        dummy_head = ListNode(next=head)\n",
    "        current = dummy_head\n",
    "        while current.next and current.next.next:\n",
    "            tempt = current.next\n",
    "            tempt2 = tempt.next\n",
    "            tempt3 = tempt2.next\n",
    "\n",
    "            current.next = tempt2   # 先保留再赋值,我采取了一种更容易理解的方式进行编程\n",
    "            tempt2.next = tempt\n",
    "            tempt2.next.next = tempt3\n",
    "            current = current.next.next\n",
    "\n",
    "        return dummy_head.next\n",
    "\n",
    "            \n",
    "            "
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "env_py38",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "name": "python",
   "version": "3.8.18"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
